function additem(type, id, price, num) {
    var shop = cookie.get('shop'); //获取cookie
    var product = {
        "type": type,
        "id": id,
        "price": price,
        "num": num
    };

    if (shop) {
        shop = JSON.parse(shop);
        if (shop.some(elm => (elm.id == id && elm.type == type))) {
            shop.forEach((elm, i) => {
                (elm.id == id && elm.type == type) ? elm.num = num: null;
            });
        } else {
            shop.push(product);
        }
        cookie.set('shop', JSON.stringify(shop), 1);
    } else {
        shop = [];
        shop.push(product);
        cookie.set('shop', JSON.stringify(shop), 1);
    }
    cart_num();
    if (confirm('添加成功！是否前往购物车查看?')) {
        location.href = "./shop.html";
        // 解决默认事件，然上一行代码有效
        event.returnValue = false;
    }
}
// 购物车数量
function cart_num() {
    var num = 0;
    var shop = cookie.get('shop');
    if (shop) {
        shop = JSON.parse(shop);
        num = shop.length;
    }
    $('#cartNum').html('( ' + num + ' )');
}